<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
       <el-form-item label="registryKey" prop="registryKeyLike">
        <el-input v-model="queryParams.registryKeyLike" clearable size="small" style="width: 240px">
        </el-input>
      </el-form-item>
      <el-form-item label="registryValue" prop="registryValueLike">
        <el-input v-model="queryParams.registryValueLike" clearable size="small" style="width: 240px">
        </el-input>
      </el-form-item>
      
      <el-form-item>
        <search-button @click="handleQuery" :perm="['job:registry:view']" />
        <reset-button @click="resetQuery" :perm="['job:registry:view']" />
      </el-form-item>
    </el-form> -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @query-table="getList" />
    </el-row>
    <el-table v-loading="loading" :data="jobRegistryList">
      <el-table-column prop="id" label="注册ID" align="center" width="120" />
      <el-table-column prop="registryGroup" label="注册类型" align="center" width="120" />
      <el-table-column prop="registryKey" label="注册AppName" align="center" min-width="160" :show-overflow-tooltip="true" />
      <el-table-column prop="registryValue" label="节点地址" align="center" min-width="160" :show-overflow-tooltip="true" />
      <el-table-column prop="updateTime" label="注册时间" align="center" width="160" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="120">
        <template #default="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="showJobHandlers(scope.row)">查看JobHandlers</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    <!-- 查看JobHandles -->
    <drag-dialog v-el-drag-dialog :title="showFlowTitle" :close-on-click-modal="false" v-model="showFlowOpen" width="80%" append-to-body>
      <el-table v-loading="loading" :data="jobHandlers" style="width: 100%">
        <el-table-column label="Handler名称" prop="label" min-width="220" align="center" />
        <el-table-column label="Handler值" prop="value" min-width="220" align="center" />
        <el-table-column label="参数列表" min-width="480" align="center">
          <template #default="scope">
            <el-table
              v-if="scope.row.jobHandlerParams && scope.row.jobHandlerParams.length>0" :data="scope.row.jobHandlerParams" size="mini"
              style="width: 100%" max-height="200" border>
              <el-table-column label="参数Key" prop="key" min-width="120" align="center" />
              <el-table-column label="参数名" prop="label" min-width="120" align="center" />
              <el-table-column label="默认值" prop="dftValue" min-width="120" align="center" />
              <el-table-column label="描述" prop="desc" min-width="120" />
            </el-table>
            <span v-else class="text-danger">无参数</span>
          </template>
        </el-table-column>
      </el-table>
    </drag-dialog>
  </div>

</template>

<script>
import { listJobRegistry, listJobHandlers } from "@job/api/job/registry";

export default {
  name: "JobRegistry",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格树数据
      jobRegistryList: [],
      // 弹出层标题
      title: "",
      showFlowTitle: "",
      showFlowOpen: false,
      // 是否显示弹出层
      open: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      jobHandlers: [],
    }
  },
  created() {
    this.getList();
  },
  methods: {
    // 查询调度日志列表
    getList() {
      this.loading = true;
      listJobRegistry(this.queryParams).then(
        response => {
          this.jobRegistryList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看按钮操作 */
    showJobHandlers(row) {
      this.loading = true;
      this.jobHandlers = []
      this.showFlowTitle = "查看JobHandles";
      this.showFlowOpen = true;
      listJobHandlers(row.id).then(
        response => {
          this.loading = false;
          this.jobHandlers = response.data;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
  }

}
</script>

<style lang="scss" scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>